var error_msg_765 = ""; function validate_email_765(mail) { if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(mail)) { return (true); } error_msg_765 = "Имэйл хаягаа зөв оруулна уу"; return (false); } function getCookie_765(cname) { var name_765 = cname + "="; var decodedCookie_765 = decodeURIComponent(document.cookie); var ca_765 = decodedCookie_765.split(';'); for(var i = 0; i < ca_765.length; i++) { var c_765 = ca_765[i]; while (c_765.charAt(0) == ' ') { c_765 = c_765.substring(1); } if (c_765.indexOf(name_765) == 0) { return c_765.substring(name_765.length, c_765.length); } } return ""; } function subscribe_submit_765(){ var form_765 = document.querySelector('#subscribe-form-765'); var data_765 = new FormData(form_765); var url_765 = "/api.php/subscription/save?site_id=608&id=765" + '&cookie_id=' + getCookie_765("cookie_id") + '&short_cookie_id=' + getCookie_765("short_cookie_id"); var xhr_765 = new XMLHttpRequest(); if (window.XMLHttpRequest) { // Mozilla, Safari, ... var xhr_765 = new XMLHttpRequest(); } else if (window.ActiveXObject) { // IE var xhr_765 = new ActiveXObject("Microsoft.XMLHTTP"); } xhr_765.open('POST', url_765, true); xhr_765.onload = function () { /* do something to response */ console.log(this.responseText); document.getElementById("subscription-form-container-765").innerHTML = this.responseText; }; var valid_765 = 1; if(form_765.querySelector('input[name="subscriber[name]"]')){ if(form_765.querySelector('input[name="subscriber[name]"]').value.trim().length > 0){ }else{ valid_765 = 0; form_765.querySelector('input[name="subscriber[name]"]').setAttribute("style", "border-color: red;"); } } if(form_765.querySelector('input[name="subscriber[email]"]')){ if(form_765.querySelector('input[name="subscriber[email]"]').value.trim().length > 0){ }else{ valid_765 = 0; form_765.querySelector('input[name="subscriber[email]"]').setAttribute("style", "border-color: red;"); } } if(form_765.querySelector('input[name="subscriber[phone]"]')){ if(form_765.querySelector('input[name="subscriber[phone]"]').value.trim().length > 0){ }else{ valid_765 = 0; form_765.querySelector('input[name="subscriber[phone]"]').setAttribute("style", "border-color: red;"); } } if(form_765.querySelector('input[name="subscription[company_name]"]')){ if(form_765.querySelector('input[name="subscription[company_name]"]').value.trim().length > 0){ }else{ valid_765 = 0; form_765.querySelector('input[name="subscription[company_name]"]').setAttribute("style", "border-color: red;"); } } if(form_765.querySelector('input[name="subscription[company_position]"]')){ if(form_765.querySelector('input[name="subscription[company_position]"]').value.trim().length > 0){ }else{ valid_765 = 0; form_765.querySelector('input[name="subscription[company_position]"]').setAttribute("style", "border-color: red;"); } } if(form_765.querySelector('input[name="subscription[title]"]')){ if(form_765.querySelector('input[name="subscription[title]"]').value.trim().length > 0){ }else{ valid_765 = 0; form_765.querySelector('input[name="subscription[title]"]').setAttribute("style", "border-color: red;"); } } if(form_765.querySelector('textarea[name="subscription[body]"]')){ if(form_765.querySelector('textarea[name="subscription[body]"]').value.trim().length > 0){ }else{ valid_765 = 0; form_765.querySelector('textarea[name="subscription[body]"]').setAttribute("style", "border-color: red;"); } } if(valid_765 == 0){ error_msg_765 = "Талбаруудыг бүрэн бөглөнө үү!"; } if(!validate_email_765(form_765.querySelector('input[name="subscriber[email]"]').value)){ form_765.querySelector('input[name="subscriber[email]"]').style="border-color: red;"; valid_765 = 0; }else{ } if(valid_765){ document.querySelector('#subscribe-form-765').style.display = "none"; document.querySelector('#subscription-form-loading-765').style.display = "inline"; xhr_765.send(data_765); }else{ alert(error_msg_765); } } // function postRequest_765(strURL) { var xmlHttp_765; if (window.XMLHttpRequest) { // Mozilla, Safari, ... var xmlHttp_765 = new XMLHttpRequest(); } else if (window.ActiveXObject) { // IE var xmlHttp_765 = new ActiveXObject("Microsoft.XMLHTTP"); } xmlHttp_765.open('POST', strURL, true); xmlHttp_765.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); xmlHttp_765.onreadystatechange = function() { if (xmlHttp_765.readyState == 4) { updatepage_765(xmlHttp_765.responseText); } } xmlHttp_765.send(strURL); } // function updatepage_765(str){ document.getElementById("subscription-form-container-765").innerHTML = str; } //'//amaicotravels.mn' + var get_url_765 = '/api.php/subscription/renderform?site_id=608' + '&id=765' + '&placeholder[subscriber][name]=Your name&placeholder[subscriber][email]=Email&placeholder[subscription][title]=Title&placeholder[subscription][body]=Content&send=Send' ; postRequest_765(get_url_765);